package com.example.shoppingmallspringboot.controller;

import com.example.shoppingmallspringboot.entity.UserAddress;
import com.example.shoppingmallspringboot.service.UserAddressService;
import com.example.shoppingmallspringboot.util.FwResult;
import com.example.shoppingmallspringboot.vo.CartVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "UserAddressController",description = "用户地址控制器")
@RestController
public class UserAddressController {
    @Autowired
    UserAddressService userAddressService;
    @GetMapping("/address/user/{userId}")
    @Operation(summary = "获取用户地址",description = "用户id为参数")
    public FwResult getUserAddress(@PathVariable("userId") Integer userId){
        return userAddressService.getUserAddress(userId);
    }
    @PostMapping ("/address/delete")
    @Operation(summary = "用户删除地址",description = "地址id为参数")
    public FwResult deleteUserAddress(@RequestBody Integer id){
        return userAddressService.deleteAddress(id);
    }
    @PostMapping ("/address/update")
    @Operation(summary = "用户添加以及编辑地址",description = "UserAddress类为参数")
    public FwResult deleteUserAddress(@RequestBody UserAddress userAddress){
        return userAddressService.updateUserAddress(userAddress);
    }
    @PostMapping ("/address/isDefault")
    @Operation(summary = "用户修改默认地址",description = "地址id为参数")
    public FwResult modifyUserAddressIsDefault(@RequestBody UserAddress userAddress){
        System.out.println(userAddress);
        return userAddressService.modifyAddressIsDefault(userAddress);
    }
}
